import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:leader_help/page/home/key_point/key_point_macroscopic/key_point_big_logic.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/icon_util.dart';
import 'package:leader_help/utils/img_util.dart';
import 'package:leader_help/value/topcolors.dart';

import 'key_think_tank_detail_logic.dart';

class KeyThinkTankDetailPage extends StatefulWidget {
  const KeyThinkTankDetailPage({Key? key}) : super(key: key);

  @override
  _KeyThinkTankDetailPageState createState() => _KeyThinkTankDetailPageState();
}

class _KeyThinkTankDetailPageState extends State<KeyThinkTankDetailPage> {
  final logic = Get.put(KeyThinkTankDetailLogic());
  final state = Get.find<KeyThinkTankDetailLogic>().state;

  final pointLogic = Get.put(KeyPointBigLogic());


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: detailAppBar(context, title: "智库详情",
        actions: [
          Container(
            margin: EdgeInsets.only(right: 10.r),
            child: InkWell(
              child: Row(
                children: [
                  const Icon(ProIconUtil.entrust, size: 18, color: Colors.white,),
                  SizedBox(width: 2.r,),
                  const Text("课题委托", style: TextStyle(color: Colors.white, fontSize: 14),),
                ],
              ),
              onTap: () {

              },
            ),
          ),
        ],
      ),
      body: Column(
        children: [
          Container(
            margin: EdgeInsets.only(left: 15.r),
            child: Row(
              children: [
                Image.asset("u781.jpg".imgPathTask, width: 80.r,),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text("国务院发展研究中心", style: TextStyle(color: Color(0xff1977FF), fontSize: 16),),
                    SizedBox(height: 10.r,),
                    Row(
                      children: [
                        Container(
                          padding: EdgeInsets.only(left: 5.r, right: 5.r, top: 0.r, bottom: 2.r),
                          decoration: BoxDecoration(
                            color: const Color(0xffF8D0D5),
                            borderRadius: BorderRadius.circular(2.r),
                          ),
                          child: Text("国家高端智库建设试点单位", style: TextStyle(color: TopColors.main_red, fontSize: 11),),
                        ),

                        Container(
                          margin: EdgeInsets.only(left: 10.r),
                          padding: EdgeInsets.only(left: 5.r, right: 5.r, top: 0.r, bottom: 2.r),
                          decoration: BoxDecoration(
                            color: const Color(0xffB8D5FF),
                            borderRadius: BorderRadius.circular(2.r),
                          ),
                          child: const Text("全球智库排名34位", style: TextStyle(color: Color(0xff70abff), fontSize: 11),),
                        ),
                      ],
                    )
                  ],
                )
              ],
            ),
          ),
          TabBar(
            tabs: [for (final tab in state.tabs) Tab(text: tab,)],
            indicatorColor: TopColors.main_red,
            indicator: BoxDecoration(
                borderRadius: BorderRadius.circular(2),
                color: TopColors.main_red),
            indicatorPadding: const EdgeInsets.only(left: 20, right: 20, top: 40, bottom: 5),
            // 字体颜色
            labelColor: TopColors.main_red,
            labelStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
            labelPadding: const EdgeInsets.only(left: 13, right: 13),
            // 没有选中字体颜色
            unselectedLabelColor: TopColors.black_33,
            unselectedLabelStyle: const TextStyle(fontSize: 15),
            // 是否滚动
            isScrollable: false,
            // 控制器
            controller: logic.controller,
            physics: const BouncingScrollPhysics(),
          ),
          Divider(
            height: 1, color: TopColors.gray_line,
          ),
          Flexible(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    padding: EdgeInsets.only(left: 10.r, right: 10.r, top: 8.r, bottom: 10.r),
                    child: Column(
                      children: [
                        Row(
                          children: [
                            Container(
                              margin: EdgeInsets.only(right: 5.r),
                              width: 3.r,
                              height: 15.r,
                              color: TopColors.main_red,
                            ),
                            Text("基本简介", style: TextStyle(color: TopColors.black_33, fontSize: 15),),
                          ],
                        ),
                        Container(
                          padding: EdgeInsets.only(left: 10.r, right: 10.r, top: 5.r),
                          child: Text("国务院发展研究中心是从事综合性政策研究和决策咨询的国务院直属事业单位。主要职能是研究中国国民经济、社会发展和改革开放中的全局性、战略性、前瞻性、长期性以及热点、难点问题，开展对重大政策的独立评估和客观解读，为党中央、国务院提供政策建议和咨询意见。",
                            style: TextStyle(color: TopColors.black_33, fontSize: 15),
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(left: 10.r, right: 10.r, top: 8.r, bottom: 10.r),
                    child: Column(
                      children: [
                        Row(
                          children: [
                            Container(
                              margin: EdgeInsets.only(right: 5.r),
                              width: 3.r,
                              height: 15.r,
                              color: TopColors.main_red,
                            ),
                            Expanded(child: Text("重要专家", style: TextStyle(color: TopColors.black_33, fontSize: 15),)),
                            InkWell(
                              child: Row(
                                children: [
                                  Text("更多", style: TextStyle(color: TopColors.black_66, fontSize: 14),),
                                  Icon(Icons.arrow_forward_ios, size: 14, color: TopColors.black_66,)
                                ],
                              ),
                            ),
                          ],
                        ),
                        ListView.builder(
                            shrinkWrap: true, //解决无线高度问题 解决SingleChildScrollView 和listview冲突问题 ListView.builder
                            itemCount: pointLogic.state.name.length,
                            physics: const NeverScrollableScrollPhysics(),
                            itemBuilder: (BuildContext context, int index) {
                              return panelListItem(index == 0 ? true : false, pointLogic.state.name[index], pointLogic.state.position[index], pointLogic.state.research[index]);
                            }
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(left: 10.r, right: 10.r, top: 8.r, bottom: 10.r),
                    child: Column(
                      children: [
                        Row(
                          children: [
                            Container(
                              margin: EdgeInsets.only(right: 5.r),
                              width: 3.r,
                              height: 15.r,
                              color: TopColors.main_red,
                            ),
                            Expanded(child: Text("主要作品", style: TextStyle(color: TopColors.black_33, fontSize: 15),)),
                            InkWell(
                              child: Row(
                                children: [
                                  Text("更多", style: TextStyle(color: TopColors.black_66, fontSize: 14),),
                                  Icon(Icons.arrow_forward_ios, size: 13, color: TopColors.black_66,)
                                ],
                              ),
                            ),
                          ],
                        ),
                        ListView.builder(
                            shrinkWrap: true, //解决无线高度问题 解决SingleChildScrollView 和listview冲突问题 ListView.builder
                            itemCount: pointLogic.state.name.length,
                            // 禁止滑动
                            physics: const NeverScrollableScrollPhysics(),
                            itemBuilder: (BuildContext context, int index) {
                              return worksListItem();
                            }
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(left: 10.r, right: 10.r, top: 20.r, bottom: 10.r),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Container(
                              margin: EdgeInsets.only(right: 5.r),
                              width: 3.r,
                              height: 15.r,
                              color: TopColors.main_red,
                            ),
                            Expanded(child: Text("其他信息", style: TextStyle(color: TopColors.black_33, fontSize: 15),)),
                          ],
                        ),
                        SizedBox(height: 10.r,),
                        Text("官  网：", style: TextStyle(color: TopColors.black_33, fontSize: 15),),
                        const Text("https://www.drc.gov.cn/", style: TextStyle(
                          decoration: TextDecoration.none,
                          color: Color(0xFFA2B5F3),
                          fontSize: 15,
                          fontWeight: FontWeight.bold,
                        ),),
                        SizedBox(height: 10.r,),
                        Text("研究方向：", style: TextStyle(color: TopColors.black_33, fontSize: 15),),
                        ListView.builder(
                            shrinkWrap: true, //解决无线高度问题 解决SingleChildScrollView 和listview冲突问题 ListView.builder
                            itemCount: logic.state.direction.length,
                            physics: const NeverScrollableScrollPhysics(),
                            itemBuilder: (BuildContext context, int index) {
                              return Container(
                                padding: EdgeInsets.only(top: 5.r, bottom: 5.r),
                                child: Text(state.direction[index], style: TextStyle(color: TopColors.black_33, fontSize: 15),)
                              );
                            }
                        ),
                      ],
                    ),
                  ),

                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<KeyThinkTankDetailLogic>();
    Get.delete<KeyPointBigLogic>();
    super.dispose();
  }

  /// 重要专家
  Widget panelListItem (bool visible, String name, String position, String research) {
    return Container(
      margin:EdgeInsets.fromLTRB(5.r, 5.r, 5.r, 5.r),
      decoration: BoxDecoration(
        color: TopColors.gray_line,
        borderRadius: BorderRadius.circular(5.r),
      ),
      child: Container(
        margin:EdgeInsets.all(2.r),
        padding: EdgeInsets.all(5.r),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(5.r),
        ),
        child: Stack(
          children: [
            Visibility(
              visible: visible,
              child:
              Align(alignment: Alignment.topRight, child: Image.asset("download.png".imgPathTask, height: 30.r),
              ),
            ),
            Column(
              children: [
                Row(
                  children: [
                    Image.asset("avatar_default.png".imgPathMe, height: 35.r,),
                    SizedBox(width: 5.r,),
                    Text(name, style: TextStyle(color: TopColors.black_33, fontSize: 14),),
                    SizedBox(width: 8.r,),
                    Flexible(
                      child: Text(
                        position,
                        style: TextStyle(color: TopColors.black_66, fontSize: 13),
                        maxLines: 2,
                        softWrap: true,
                        overflow: TextOverflow.ellipsis,
                      ),
                    )
                  ],
                ),
                Row(
                  children: [
                    Text("研究领域：", style: TextStyle(color: TopColors.black_66, fontSize: 13),),
                    Text(research, style: TextStyle(color: TopColors.main_red, fontSize: 13),)
                  ],
                ),
                SizedBox(height: 10.r,),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Container(
                      alignment: Alignment.center,
                      padding: EdgeInsets.only(left: 20.r, right: 20.r, top: 2.r, bottom: 4.r),
                      margin:EdgeInsets.only(left: 20.r),
                      decoration: BoxDecoration(
                        border: Border.all(color: TopColors.main_red, width: 1),
                        borderRadius: BorderRadius.circular(5.r),
                      ),
                      child: Text("他的观点",
                        style: TextStyle(color: TopColors.black_33, fontSize: 13),),
                    ),
                    Container(
                      alignment: Alignment.center,
                      padding: EdgeInsets.only(left: 20.r, right: 20.r, top: 2.r, bottom: 4.r),
                      margin:EdgeInsets.only(right: 20.r),
                      decoration: BoxDecoration(
                        border: Border.all(color: TopColors.main_red, width: 1),
                        borderRadius: BorderRadius.circular(5.r),
                      ),
                      child: Text("委托课题",
                        style: TextStyle(color: TopColors.black_33, fontSize: 13),),
                    ),

                  ],
                ),
              ],
            )
          ],
        ),
      ),
    );
  }

  /// 主要作品
  Widget worksListItem () {
    return Container(
      margin:EdgeInsets.fromLTRB(5.r, 5.r, 5.r, 5.r),
      decoration: BoxDecoration(
        color: TopColors.gray_line,
        borderRadius: BorderRadius.circular(5.r),
      ),
      child: Container(
        margin:EdgeInsets.all(2.r),
        padding: EdgeInsets.all(5.r),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(5.r),
        ),
        child: Column(
          children: [
            RichText(
              text: TextSpan(
                  children: [
                    WidgetSpan(
                      child: Container(
                        decoration: BoxDecoration(
                          border: Border.all(color: TopColors.top_ju, width: 1),
                          borderRadius: BorderRadius.circular(2.r),
                        ),
                        child: Text("研究报告", style: TextStyle(color: TopColors.top_ju, fontSize: 11),),
                      ),
                    ),
                    WidgetSpan(
                      child: SizedBox(width: 5.r,),
                    ),
                    TextSpan(text: "《在加快构建新发展格局中增强产业链供应链韧性》", style: TextStyle(color: TopColors.black_33, fontSize: 14,),),
                    WidgetSpan(
                      child: SizedBox(width: 5.r,),
                    ),
                    const TextSpan(text: "--2021-12-02", style: TextStyle(color: Color(0xff70abff), fontSize: 14,),),
                  ]
              ),
            ),
            RichText(
              text: TextSpan(
                children: [
                  WidgetSpan(

                    child: SizedBox(
                      width: 35.r,
                      child: Row(
                        children: [
                          Text("观点", style: TextStyle(color: TopColors.black_33, fontSize: 15),),
                          Container(
                            margin: EdgeInsets.only(left: 2.r),
                            width: 2.r,
                            height: 15.r,
                            color: TopColors.black_66,
                          ),
                        ],
                      ),
                    ),
                  ),
                  WidgetSpan(
                    child: SizedBox(width: 5.r,),
                  ),
                  TextSpan(text: "我们认为，应以深化供给侧结构性改革为主线，促进制造业“走出去”与完善创新链，优化供应链，提升产业链，升级价值链相结合；合理有序引导区域产业转移和优化制造业全球布局，全面提升我国在全球产业链中的优势地位和运营能力；坚持软硬结合、协同发展，健全和完善制造业对外直接投资政策保障体系，为早日建成制造强国提供重要支撑保障。",
                    style: TextStyle(color: TopColors.black_33, fontSize: 14,),
                  ),
                ]
              ),
            ),
          ],
        ),
      ),
    );
  }

}